package com.icangya.DAO.impl;

import com.icangya.DAO.IGoodsUpgradeRecordDAO;
import com.icangya.Utils.SQLUtilt;
import com.icangya.domain.GoodsUpgradeRecord;
import com.icangya.domain.UserPointsRecord;
import org.hibernate.Query;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

import static com.icangya.Value.FootBall.FOOT_PAGE_ROW;


@Repository
public class GoodsUpgradeRecordDAOImpl extends  BaseDAO<GoodsUpgradeRecord> implements IGoodsUpgradeRecordDAO {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public List<GoodsUpgradeRecord> getGoodsUpgradeByUserId(long uid) {
        Session session=  getHibernateTemplate().getSessionFactory().getCurrentSession();
        String hql=" FROM GoodsUpgradeRecord gr where gr.uid='"+uid+"'order by gr.createTime desc";
        Query query=session.createQuery(hql);
       query.setMaxResults(10);
        List list=query.list();
        if(list == null || list.size() < 1) {
            return null;
        }
        return list;
    }

    @Override
    public List<Object> getGoodsUpgradeByUserIdPaging(long uid, Integer pageNum) {
        String hql="FROM GoodsUpgradeRecord er where er.uid='"+uid+"' order by er.createTime desc";
        String count = "SELECT COUNT(er) " + hql;
        Long total = (Long) getHibernateTemplate().find(count).get(0);
        return SQLUtilt.getIstance().doPage(getHibernateTemplate(), hql, total, pageNum, FOOT_PAGE_ROW);
    }
}
